<?php

namespace workin\modules\increment\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use workin\modules\increment\models\MortgageSignupHuirong;

/**
 * MortgageSignupHuirongSearch represents the model behind the search form about `workin\modules\increment\models\MortgageSignupHuirong`.
 */
class MortgageSignupHuirongSearch extends MortgageSignupHuirong
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['grant_key', 'api_key', 'business_code', 'plate_number', 'vehicle_number', 'call_back', 'order_report_id', 'report_id', 'search_index'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = MortgageSignupHuirong::find()->orderBy(['id'=>SORT_DESC]);

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
        ]);

        $query->andFilterWhere(['like', 'grant_key', $this->grant_key])
            ->andFilterWhere(['like', 'api_key', $this->api_key])
            ->andFilterWhere(['like', 'business_code', $this->business_code])
            ->andFilterWhere(['like', 'plate_number', $this->plate_number])
            ->andFilterWhere(['like', 'vehicle_number', $this->vehicle_number])
            ->andFilterWhere(['like', 'call_back', $this->call_back])
            ->andFilterWhere(['like', 'order_report_id', $this->order_report_id])
            ->andFilterWhere(['like', 'report_id', $this->report_id])
            ->andFilterWhere(['like', 'search_index', $this->search_index]);

        return $dataProvider;
    }
}